<template>
    <div class="navbar">
        <van-nav-bar :title="pagetitle"  :left-text="lefttitle"   :left-arrow="leftarrow"   @click-left="onClickLeft"   @click-right="onClickRight"  >
            <van-icon name="cross" slot="right" class="white"/>
        </van-nav-bar>
    </div>
</template>

<script>
    import { NavBar,Icon } from 'vant'
    import {closeBrowserPage } from '@/utils/closeBrowserPage'
    import {getQuery } from '@/utils/auth'
    export default {
        components: {
            [NavBar.name]: NavBar,
            [Icon.name]: Icon
        },
        data(){
            return {
                pagetitle:'',
                isopenproblem:false,
                query:{},
                lefttitle:''
            }
        },
        props:{
            isrecord:{
                type: Boolean,
                default: true
            },
            leftarrow:{
                type: Boolean,
                default: true
            },
            title:{
                type: String,
                default: '客服'
            },
            backtype:{
                type: Boolean,
                default: false
            },
            isCenterPage:{
                type: Boolean,
                default: false
            }
        },
        created() {
        },
        mounted() {
            this.togTitle();
        },
        methods: {
            togTitle(){
                this.query=getQuery()
                if(this.query.openProblem){
                    this.isopenproblem =true
                }
                if(this.isCenterPage){
                    this.pagetitle='在线客服'
                }else{
                    this.pagetitle=this.title+'帮助中心'
                }
                if(this.isrecord&&location.href.indexOf('rechargerecord')===-1&&location.href.indexOf('customerServicePage')===-1&&this.query.openProblem==='1'){
                    this.lefttitle='提交记录'
                } else{
                    this.lefttitle='返回'
                }
            },
            onClickLeft() {

                 if(this.isCenterPage){
                    if(this.backtype){
                        if(this.backtype){
                            this.$emit('update:backtype', false)
                        }
                    }
                    else{
                        console.log(`返回游戏大厅`)
                        closeBrowserPage();

                    }
                }else if(!this.isopenproblem){
                    console.log(`返回游戏大厅`)
                    closeBrowserPage();
                }else  if(this.isrecord&&location.href.indexOf('rechargerecord')===-1&&this.query.openProblem==='1'){
                     const QuerySerch = location.search
                     window.location.href = `/rechargerecord${QuerySerch}`
                 }else{
                    console.log(`返回咨询主页面`)
                    const QuerySerch = location.search
                    location.href = `/customerServicePage${QuerySerch}`
                }
            },
            onClickRight(){
                console.log(`返回游戏大厅`)
                closeBrowserPage();
            }
        }
    }
</script>

